package com.kanshu.ksgb.fastread.doudou.common.net.bean;

import com.kanshu.ksgb.fastread.doudou.R;
import com.kanshu.ksgb.fastread.doudou.app.Xutils;
import com.kanshu.ksgb.fastread.doudou.common.business.manager.MMKVDefaultManager;
import com.kanshu.ksgb.fastread.doudou.common.business.manager.MMKVUserManager;
import com.kanshu.ksgb.fastread.doudou.common.business.utils.UserUtils;
import com.kanshu.ksgb.fastread.doudou.common.util.JsonUtils;
import com.kanshu.ksgb.fastread.doudou.common.util.MD5Util;
import com.kanshu.ksgb.fastread.doudou.common.util.Utils;

import java.util.Random;


/**
 * 项目名称：client
 * 类描述：网络请求参数基类
 * 创建人：wanchunyang
 * 创建时间：2017/4/25 11:55
 * 修改人：wanchunyang
 * 修改时间：2017/4/25 11:55
 * 修改备注：
 */
public class BaseRequestParams {
    public String device_id;
    public String req_time;
    public String app_key;
    public String app_token;
    public String user_id;
    // 书库版本 到时看后台配置
    public String version;
    // 后台分配给客户端的appid
    public String app_id;
    // 1：男频；2：女频
    public String site;
    // 极光推送注册id 用于单推某一个人
    public String registration_id;
    // 渠道id
    public String channel_id;
    // 免费版本和付费版本 0付费 1免费
    public int is_free_version;
    // api version 默认从2开始
    public int api_version = 3;
    public String __flush_cache = "0";
    // app版本标识
    public String version_name;
    // 登录状态  默认 0 未未登录  1 为登录状态
    public String islogin = "0";

    public BaseRequestParams() {
        device_id = UserUtils.getDeviceId();
        req_time = System.currentTimeMillis() + "" + (new Random().nextInt(8999) + 1000);
        app_key = Xutils.getContext().getResources().getString(R.string.app_key);
        app_token = MD5Util.md5(device_id + "#" + req_time + "#" + Xutils.getContext().getResources().getString(R.string.app_secret));
        user_id = UserUtils.getUserId();
        app_id = Xutils.getContext().getString(R.string.app_id);
        version = Xutils.getContext().getString(R.string.version);
        site = MMKVUserManager.getInstance().getLoginSex();
        registration_id = UserUtils.getJpushRegistrationId();
        channel_id = UserUtils.getChannelId();
        is_free_version = MMKVDefaultManager.getInstance().isFreeVersion();
        __flush_cache = MMKVDefaultManager.getInstance().isClearCache() ? "1" : "0";
        version_name = Utils.getVersionName(Xutils.getContext());
        islogin = MMKVUserManager.getInstance().isUserLogin() ? "1" : "0";
    }

    public String toJsonStr() {
        return JsonUtils.bean2Json(this);
    }

}
